﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering.View_Operaction;
using Catering_Rules;

namespace Catering.UCPanle
{
    public partial class UCDDLToolWithDate : System.Web.UI.UserControl
    {
        private string AREAID = "";
        private string CLASSID = "";
        private string Year = "";
        FromRecords frRules = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-M'})");
                loadPage();
            }
        }
        private void loadPage()
        {
            if (Session["User"] != null)
            {
                string userid = Session["PersonnelID"].ToString();
                int companyid = 0;
                int groupid = 0;
                int classid = 0;
                bool isAdmin = false;
                Bind_Data_to_Controls.GetCompanyByCurrentUser(userid, out companyid, out groupid, out classid, out isAdmin);
                Bind_Data_to_Controls.Bind_Area_ddl(ddl_Area, isAdmin, groupid, companyid);
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_Area.SelectedItem, ddl_class, isAdmin, classid);
            }
        }

        ///// <summary>
        ///// 是否显示月份
        ///// </summary>
        //public Boolean DisplayMonth
        //{
        //    get
        //    {
        //        return (Boolean)ViewState["allowDuplicates"];
        //    }
        //    set
        //    {
        //        if (!value)
        //        {
        //            Label2.Visible = false;
        //            ddl_Month.Visible = false;
        //        }
        //    }
        //}

        /// <summary>
        /// 是否显示年
        /// </summary>
        public Boolean DisplayYear
        {
            get
            {
                return (Boolean)ViewState["allowDuplicates"];
            }
            set
            {
                Label1.Visible = value;
                TextBox2.Visible = value;
            }
        }

        public Boolean ChoiseYearORMonth
        {
            get
            {
                return (Boolean)ViewState["allowDuplicates"];
            }
            set
            {
                if (value)
                {
                    TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-M'})");
                    Label1.Text = "选择年月：";
                }
                else
                {
                    TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy'})");
                    Label1.Text = "选择年：";
                }
            }
        }

        /// <summary>
        /// 是否显示文本框
        /// </summary>
        public Boolean DisplayTextBox
        {
            get
            {
                return (Boolean)ViewState["allowDuplicates"];
            }
            set
            {
                Label3.Visible = value;
                TextBox1.Visible = value;
            }

        }

        /// <summary>
        /// 获取作业区ID
        /// </summary>
        /// <returns></returns>
        public string GetDDL_Area()
        {
            if (ddl_Area.SelectedItem != null)
            {
                AREAID = ddl_Area.SelectedItem.Value;
            }
            return AREAID;
        }
        /// <summary>
        /// 获取班组ID
        /// </summary>
        /// <returns></returns>
        public string GetDDL_Class()
        {
            if (ddl_class.SelectedItem != null)
            {
                CLASSID = ddl_class.SelectedItem.Value;
            }
            return CLASSID;
        }
        /// <summary>
        /// 获取管事
        /// </summary>
        /// <returns></returns>
        public string GetTextBox()
        {
            string text = "";
            if (string.IsNullOrEmpty(TextBox1.Text))
            {
                text = TextBox1.Text;
            }
            return text;
        }
        /// <summary>
        /// 返回已选择时间
        /// </summary>
        /// <returns></returns>
        public DateTime GetDateTime()
        {
            DateTime dTime = DateTime.Parse("1949-10-01");
            if (!string.IsNullOrEmpty(TextBox2.Text))
            {
                if (TextBox2.Text.Length == 4)
                {
                    DateTime.TryParse(TextBox2.Text + "-01-01 00:00:11", out dTime);
                }
                else if (TextBox2.Text.Length > 4)
                {
                    DateTime.TryParse(TextBox2.Text, out dTime);
                }

            }
            return dTime;
        }

        protected void ddl_Area_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddl_Area.SelectedItem != null)
            {
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_Area.SelectedItem, ddl_class);
            }
        }

    }
}